import { h } from 'snabbdom'

/**
 * 渲染“回复”元素到编辑器
 * @param elem 回复元素
 * @param children 元素子节点，void 元素可忽略
 * @param editor 编辑器实例
 * @returns vNode 节点
 */
function render(elem, children, editor) {
  const { userName, time, content } = elem

  const vNode = h('p', { props: { className: 'reply-message' } }, [
    h('span', { props: { className: 'reply-message-user-name' } }, [userName]),
    h('span', { props: { className: 'reply-message-time' } }, [time])
  ])

  const contentNode = h('p', { props: { className: 'reply-message-content', innerHTML: content } })

  return h('blockquote', { props: { contentEditable: false, className: 'reply-message-blockquote' } }, [
    vNode,
    contentNode
  ])
}

export const renderElemConf = { type: 'reply', renderElem: render }
